package com.kayt.cyberBar.cuser.business.dao.impl;

import java.sql.SQLException;
import java.util.LinkedHashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.kayt.cyberBar.common.PageData;
import com.kayt.cyberBar.common.dao.EntityDao;
import com.kayt.cyberBar.cuser.business.dao.ISheetStoreCurrentWorkDao;
import com.kayt.cyberBar.cuser.business.entity.po.BSheetStoreCurrentWork;

@Repository("sheetStoreCurrentWorkDao")
public class SheetStoreCurrentWorkDaoImpl implements ISheetStoreCurrentWorkDao {
	@Autowired
	private EntityDao entityDao;
	@Override
	public Integer save(BSheetStoreCurrentWork entity) throws SQLException {
			if(entity != null){
				entityDao.save(entity);
				return 0;
			}else{
				return -1;
			}
	}

	@Override
	public Integer update(BSheetStoreCurrentWork entity) throws SQLException {
		
			if(entity != null){
				entityDao.update(entity);
				return 0;
			}else{
				return -1;
			}
	}

	@Override
	public Integer delete(Long id) {
		
			if(id != null){
				BSheetStoreCurrentWork BSheetStoreCurrentWork = findById(id);
				if(BSheetStoreCurrentWork != null){
					entityDao.delete(BSheetStoreCurrentWork);
					return 0;
				}else{
					return -1;
				}
			}else{
				return -1;
			}
	}

	@Override
	public BSheetStoreCurrentWork findById(Long id) {
		
			if(id != null){
				return entityDao.findById(id, BSheetStoreCurrentWork.class);
			}else{
				return null;
			}
	}

	@Override
	public PageData<BSheetStoreCurrentWork> findByPage(int pageNum, int pageSize, String hql, Object[] params,
			LinkedHashMap<String, String> orderMap) throws SQLException {
		return this.entityDao.getPagingData(BSheetStoreCurrentWork.class, pageNum, pageSize, hql, params, orderMap);
	}

	@Override
	public BSheetStoreCurrentWork findBSheetStoreCurrentWork(String workCode, String shiftCode, String date)
			throws SQLException {
		String sql = "select * from b_sheet_store_current_work where WORK_CODE = '" + workCode + "' and SHIFT_CODE = '"
				+ shiftCode + "' and WORK_TIME = '" + date + "'";
		List<BSheetStoreCurrentWork> currentWorkList = entityDao.getPagingDataBySql(BSheetStoreCurrentWork.class, -1, -1, sql, null);
		if(currentWorkList != null && currentWorkList.size() != 0){
			return currentWorkList.get(0);
		}else{
			return null;
		}
	}

	@Override
	public void batchDelete(List<BSheetStoreCurrentWork> entityList) {
		entityDao.batchDelete(entityList);
	}
}
